<?php
//我的提案

function xinxi_default(){
    xinxi_page();
}

function xinxi_page(){
    _output_template(0,'xinxi');
}

function _zhengxie_outputXinxi(){
    !isset($_REQUEST['mod']) == true ? $mod = 1 : $mod = $_REQUEST['mod'];
    !isset($_REQUEST['page']) == true ? $page = 1 : $page = $_REQUEST['page'];
    $str="  <div style='border-radius: 10px;height: 97%;background-color: white; -webkit-box-shadow: #e2f0fe 0px 0px 10px;-moz-box-shadow: #e2f0fe 0px 0px 10px;box-shadow: #e2f0fe 0px 0px 10px;'>
                <div style='width: 100%; height: 90px;'>
                    <div style='width: 100%;height: 83px'>";

            $buttonIMG = array(
                array('check'=>'/images/message/quanbo1.png','checked'=>'/images/message/quanbo2.png','name'=>'全部','mod'=>1,'class'=>'allMessage'),
                array('check'=>'/images/message/gonggao1.png','checked'=>'/images/message/gonggao2.png','name'=>'公告','mod'=>2,'class'=>'allAnnouncement'),
                array('check'=>'/images/message/renwu1.png','checked'=>'/images/message/renwu2.png','name'=>'任务','mod'=>3,'class'=>'allTask')
                /*array('check'=>'/images/message/siliao1.png','checked'=>'/images/message/siliao2.png','name'=>'私聊','mod'=>4,'class'=>'allChat'),
                array('check'=>'/images/message/qunzu1.png','checked'=>'/images/message/qunzu2.png','name'=>'群组','mod'=>5,'class'=>'allGroup')*/
            );

            foreach ($buttonIMG as $value){
                $str.=" <a href='?action=xinxi&mod=".$value['mod']."'>
                            <div style='width: 14%;height: 100%;line-height: 83px;position: relative;float: left;'>
                                <div style='width: 90px;text-indent: 40px;margin: 0 auto;background: url(".($value['mod'] == $mod ? $value['checked'] : $value['check']).") no-repeat left;'>
                                    <span style='font-size: 19px;color: #4e99ff;'>".$value['name']."</span>
                                </div>
                                <div class='".$value['class']."' style='display: none;font-size: 11px;text-align: center;border-radius: 30px;color: white;background-color: red;width: 20px;height: 20px;line-height: 20px;position: absolute;right: 0px;top: 12px;'></div>
                            </div>
                        </a>";
            }

            $str.="<a class='showdialog_xinxi' >
                        <div  style='width: 82px;height: 35px;background-color: #ffba4a;color: white;border-radius: 4px;float: right;margin-right: 30px;line-height: 35px;text-align: center;position: relative;top: 50%;transform:translateY(-50%)'>
                            <span>+</span>
                        </div>
                   </a>";

            $str.="<div style='position: relative;display: inline-block;float: right;z-index: 1;'>
                        <ul class='sub' style='display: none;list-style-type:none;position: absolute;width: 184px;height: 165px;left: -100px;top: 65px;background: url(images/xinxizhongxin/diban.png) no-repeat center;-webkit-box-shadow: #e2f0fe 10px 5px 10px;-moz-box-shadow: #e2f0fe 10px 5px 10px;box-shadow: #e2f0fe 10px 5px 10px;' >
                            <li id='1' style='font-size:16px;color: #4e99ff;margin-top: 10px;background-color:white;height:52px;text-align: center;line-height:52px;cursor:pointer;border-bottom:1px solid #eff7ff;border-top-left-radius: 5px;border-top-right-radius: 5px;'>发布公告</li>
                            <li id='2' style='font-size:16px;color: #4e99ff;background-color:white;height:52px;text-align: center;line-height:52px;cursor:pointer;border-bottom:1px solid #eff7ff;'>新建私聊</li>
                            <li id='3' style='font-size:16px;color: #4e99ff;background-color:white;height:52px;text-align: center;line-height:52px;cursor:pointer;border-bottom:1px solid #eff7ff;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px'>创建群组</li>
                        </ul>
                        <script type='text/javascript'>
                            $('.showdialog_xinxi').click(
                                function() {
                                  $('.sub').css('display')=='none' ? $ ('.sub').css('display','block'):$('.sub').css('display','none');
                                }
                            );
                            $('.sub li').each(
                                function() {
                                  $(this).mouseover(function() {                     
                                    $(this).css('background-color','#4e99ff');
                                     $(this).css('color','#fff');
                                  });
                                  
                                  $(this).mouseout(function() {
                                    $(this).css('background-color','#fff');
                                     $(this).css('color','#4e99ff');
                                  });
                                  
                                  $(this).click(function() {
                                    switch ($(this).attr('id')){
                                        case '1':
                                            window.location.href='?action=xinxi&createdialog=1';
                                            break;
                                        case '2':
                                            break;
                                        case '3':
                                            break;
                                    }
                                    
                                    $('.sub').css('display','none');
                                  });
                                }
                            );
                        </script>
                   </div>";


            $str.="</div>
                        <div style='width: 100%;height: 7px;background-color: #f7f7f7;'>";
                            foreach ($buttonIMG as $value){
                                $value['mod'] == $mod ? $str.="<div style='width: 14%;height: 100%;line-height: 80px;background-color: #4e99ff;float: left'></div>":$str.="<div style='float: left;width: 14%;height: 100%;line-height: 80px;background-color: transparent;'></div>";
                            };
                 $str.="</div>
                   </div>";

            //此处拼接(给啥拼啥)
            $str.="<input type='hidden' class='action_flag' id='".$GLOBALS['ACTION']."'>
                   <div class='list' id='".$mod."' style='width: 100%;height: 780px'>";

            $str.="</div>
                       <div  style='width: 100%;height: 110px;border-bottom: 1px solid #f7fcff'>
                            <div class='tablist' id='".$page."' style='position: relative;left: 50%;top: 30%;transform: translateX(-50%);display: inline-block'>
                                
                            </div>
                       </div>
                   </div>
                   <script>getTaskList('".$mod."');</script>";

    return $str;
}

function _zhengxie_outputXinxiDialog(){
    if (!empty($_REQUEST['taskid'])){
        $data = array();
        $sql = "select a.taskcontent,a.title,a.tasktime,a.fileid,a.checkid,b.realname,g.role from task as a left join user as b on a.userid=b.id left join usergroup as g on b.role=g.id where a.id=".$_REQUEST['taskid'];
        $result = $GLOBALS['DB']->query($sql);
        while($res=$result->fetch()) {
            $data = $res;
        }

        if (empty($data['checkid'])){
            $checkid=$_SESSION['USERID'];
        }else{
            $checkids = explode(',',$data['checkid']);
            $in = in_array($_SESSION['USERID'],$checkids);
            if ($in){
                $checkid=$data['checkid'];
            }else{
                $checkid=$data['checkid'].','.$_SESSION['USERID'];
            }
        }

        $sql = "update task set lookNum=lookNum+1,isLook=1,checkid='".$checkid."' where id=".$_REQUEST['taskid'];
        $GLOBALS['DB']->query($sql);

        $str = "<script>showdialog();</script>";
        $str .= "<div class='dialog_tongzhi' style='width:680px;height:480px;background-color: white;position: relative;top: 18%;left: 36%;border-radius: 8px;display:block'>
                   <div style='height: 82px;background-color: #3e8ffe;border-top-left-radius: 8px;border-top-right-radius: 8px;color: white;font-size: 17px;line-height: 82px;text-align: center'>
                        <span style='position: absolute;left: 50%;transform: translateX(-50%)'>".$data['title']."</span>
                        <div class='main_dialog_cuohao' onclick='dissmissdialog()' style='position: relative;top: -20px;background-image: url(images/main/cuohao.png);background-position: center;background-repeat:no-repeat;background-size: 15px;width:40px;height: 82px;float: right'></div>
                   </div>
                   
                   <div class='solide_box' style='width: 100%;height: 320px;padding-left: 54px;padding-right: 54px;padding-top: 34px'> 
                        <div> 
                            <div style='background-image: url(images/main/touxiang.png);width: 64px;height: 64px;background-repeat: no-repeat; 
                            background-position: center;background-size: 64px;float: left'></div>
                            <div style='height: 60px;line-height: 60px;float: left;color: #333;font-size: 20px;padding-left: 16px'>".$data['role']."-".$data['realname']."</div>
                            <div style='float: right;font-size: 14px;color: #999999;margin-right: 40px;height: 64px;line-height: 64px'>".$data['tasktime']."</div>
                            <div style='clear: both'></div>
                        </div>
                        <div style='margin-top: 32px'> 
                            <div style='width: 69px;height: 68px;color: #ffaa04;font-size: 16px;text-align: center;display: inline;float: left'>【公告】:</div>
                            <div style='height: 100px;float: left;width: 460px;color: #333;margin-left: 13px;font-size: 16px'>".$data['taskcontent']."</div>
                            <div style='clear: both'></div>
                            <div>
                                <div style='margin-top: 15px'>
                                    <div style='width: 64px;height: 64px;color: #333;font-size: 14px;text-align: center;display: inline;float: left'>附件 :</div>
                                    <div style='background-image: url(images/main/word.png);background-repeat: no-repeat;background-size: 20px; margin-left: 16px;background-position: center;width: 20px;height: 20px;float: left'></div>
                                    <a href='?action=xinxi&filelist=".$data['fileid']."'><div class='main_dialog_dowload' style='width: 100px;float: left;color: #8cbdff;height: 20px;line-height: 20px;font-size: 16px;margin-left: 5px'>查看/下载</div></a>
                                </div>
                            </div>
                        </div>
                   </div>
                   
                   <div style='width: 100%;height: 78px;background-color: #f0f6ff;border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;display: flex;align-items: center'> 
                       <div class='main_bottom_dialog_zhidao' onclick='dissmissdialog();' style='width: 210px;height: 48px;background-color: #3e8ffe;border-radius:10px;text-align: center;line-height: 48px;color: white;font-size: 16px;margin: 0px auto;'>
                            知道了
                       </div>
                   </div>
                </div>";
        return $str;
    }
    else if(!empty($_REQUEST['createdialog'])){
        $str = "<script>showdialog();</script>";
        $str .= "<div class='dialog_tongzhi' style='width:680px;height:480px;background-color: white;position: relative;top: 18%;left: 36%;border-radius: 8px;display:block'>
                   <div style='height: 82px;background-color: #3e8ffe;border-top-left-radius: 8px;border-top-right-radius: 8px;color: white;font-size: 17px;line-height: 82px;text-align: center'>
                        <span style='position: absolute;left: 50%;transform: translateX(-50%)'>发布公告</span>
                        <div class='main_dialog_cuohao' onclick='dissmissdialog()'
                        style='background-image: url(images/main/cuohao.png);background-position: center;background-repeat:no-repeat;background-size: 15px;width:40px;height: 82px;float: right;position: relative;top: -20px;'></div>
                   </div>
                   
                   <div style='width: 100%;height: 320px;'> 
                        <div style='width: 550px;height: 100%;margin: 0 auto'>
                            <div style='width: 550px;height: 50px;margin-top: 20px'>
                                <div style='float: left;position: relative;top: 10px;font-size: 16px;line-height: 30px;color: #444444;width: 80px;display: inline-block'>标题:</div>
                                <input class='announcement_title' placeholder='标题不少于三个字' type='text' style='font-size: 16px;background-color: #fafdff;border-radius: 4px;color: #444444;border: 1px solid #f3f9fd;margin-left: 10px;width: 454px;height: 40px;position: relative;top: 50%;transform: translateY(-50%);'>
                            </div>
                            
                            <div style='width: 100%;height: 180px;color: #333333; font-size: 18px;margin-top: 16px;'>
                                <div style='float: left;position: relative;top: 5px;font-size: 16px;line-height: 30px;color: #444444;width: 80px;display: inline-block'>正文:</div>
                                <textarea class='announcement_content' style='padding: 10px;;margin-left: 10px;overflow:auto;resize: none;;width: 454px;height: 180px; color: #666666;font-size: 16px;background-color: #fafdff;border: 1px solid #f1f5f9;-moz-box-sizing: border-box;-webkit-box-sizing: border-box;
                                -o-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;'></textarea>
                            </div>
                            
                            <div style='width: 100%;height: 50px;margin-top: 15px'>
                                <div style='font-size: 16px;line-height: 50px;text-align: center;display: inline-block;height:100%;float: left;'>
                                    添加附件:
                                </div>
                                
                                <div style='padding-left: 100px;'>
                                    <div type='text' style='color: #c9c9c9;font-size: 20px;width: 100%;height: 45px'>
                                        <div class='photo-list' style='width: 91%'>
                                            <div class='photo-grid'>
                                                <span>+</span>
                                                <input class='mobileupload_announcement' type='file' multiple>
                                            </div>
                                            <div style='clear:both'></div>
                                        </div>
                                    </div>
                                </div>
                                
                                <style>
                                    .photo-grid{
                                        height: 45px;
                                        width: 45px;
                                        color: #f2f2f2;
                                        float: left;
                                        margin-left: 1px;
                                        margin-top: 1px;
                                        margin-bottom: 1px;
                                        border-radius: 5px;
                                        background-color: #ffcf80;
                                        font-size: 30px;
                                        line-height: 45px;
                                        text-align: center;
                                        position: relative;
                                        cursor: pointer;
                                        border: 1px solid #f2f2f2
                                    }
                                    .mobileupload_announcement{
                                        position: absolute;
                                        cursor: pointer;
                                        opacity: 0;
                                        left: 0px;
                                        height: 45px;
                                        width: 45px;
                                    }
                                </style>
                                
                            </div>
                        </div>
                   </div>
                   
                   <div style='width: 100%;height: 78px;background-color: #f0f6ff;border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;display: flex;align-items: center'> 
                        <div onclick='sendAnnouncement();' style='width: 210px;height: 48px;background-color: #3e8ffe;border-radius:10px;text-align: center;line-height: 48px;color: white;font-size: 16px;margin: 0px auto;'>
                            发布
                        </div>
                   </div>
                </div>";
        return $str;
    }

    if (isset($_REQUEST['filelist'])) {
        //下载
        $str="<script>showdialog();</script>";
        $str .= "<div style='position: absolute;top: 25%;margin-left: 210px;left: 45%;transform: translateX(-50%); width: 686px;height: 480px;'>
                    <div style='background-color: #3e8ffe;background-size: 100% 100%;border-top-left-radius: 8px;border-top-right-radius: 8px;height: 82px;width: 100%;line-height: 82px;text-align: center;color: white;font-size: 20px;'>
                        <span style='position: absolute;left: 50%;transform: translateX(-50%)'>文件目录</span>
                        <div class='main_dialog_cuohao' onclick='dissmissdialog()' style='position: relative;top: -20px;background-image: url(images/main/cuohao.png);background-position: center;background-repeat:no-repeat;background-size: 15px;width:40px;height: 82px;float: right'></div>
                    </div>
                    <div style='background-color: white;height: 398px;width: 100%;border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;'>
                        <div class='solide_box' style='width: 600px;height: 398px;background-color: white;overflow: auto;padding-top: 20px;margin: 0px auto;'>
                            <span style='color: #999999'>内容下载</span>";

        if ($_REQUEST['filelist'] != 0){
            $data = array();
            $sql = "select * from enclosure where id in(".$_REQUEST['filelist'].")";
            error_log($sql);
            $result = $GLOBALS['DB']->query($sql);
            while($res=$result->fetch()) {
                $data[] = $res;
            }

            foreach ($data as $value){
                $str.="<div style='width: 100%;height: 50px;background: url(images/daifankui/wenjianjia.png) no-repeat 10px'>
                <div style='overflow: hidden;display: inline-block;margin-left: 50px;max-width: 350px;height: 50px;line-height: 50px'>".$value['enclosurename']."</div>
                <a href='".$value['enclosureurl']."' style='float: right;position: relative;top: 50%;transform: translateY(-50%)'><img style='width: 32px;height: 32px;' src='images/daifankui/xiazai.png'></a>
                <div style='color: #999999;max-width: 130px;height: 50px;line-height: 50px;margin-right: 20px;float: right'>".$value['enclosuretime']."</div>
             </div>";
            }
        }
        $str.="</div>
                    </div>
                </div>";
        return $str;
    }
    /**
     *
     * $size=filesize($file_name);
    $handle=fopen($file_name, 'r');
    Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Accept-Length: ".$size);
    Header("Content-Disposition: attachment; filename=".$file['filename']);
    while(!feof($handle)) {
    echo fread($handle, 1024000);
    sleep(1);
    }
    fclose($handle);
     *
     *
     */

}